package com.example.demo.base.login.dto;

import com.example.demo.utils.RedisUtil;
import com.example.demo.constants.BusinessExceptionCode;
import com.example.demo.domain.entity.User;
import com.example.demo.exception.BusinessException;
import lombok.Data;

import java.util.Optional;

// 用户存入登入时候的信息，如用户名，公司名等
@Data
public class UserCache {
    private User user;

    /**
     * 所属公司
     */
    private Long companyId;
    private String companyName;

    private String ip;

    public String getCompanyName() {
        return companyName;
    }

    public void setCompanyName(String companyName) {
        this.companyName = companyName;
    }

    public Long getCompanyId() {
        return companyId;
    }

    public void setCompanyId(Long companyId) {
        this.companyId = companyId;
    }

    public User getUser() {
        if (Optional.ofNullable(user).isPresent()) {
            return user;
        }else {
            throw new BusinessException(BusinessExceptionCode.NO_USERINFO);
        }
    }

    public void setUser(User user) {
        this.user = user;
    }
}
